// +----------------------------------------------------------------------
// | CmsWing [ 美业管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 psi All rights reserved.
// +----------------------------------------------------------------------
// | Author: huang <2374266244@qq.com>
// +----------------------------------------------------------------------
'use strict';
import Base from './base.js';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
	async indexAction(){	
		return this.display();
	}
	
	async cardtypelistAction(){
		if(this.isPost){
			//取出
			let glist = await this.model('or_cardtype').where({'o_id':this.userinfo.o_id}).select();
			let relist = {
				"draw": '',
				"data": glist,
				"breadcrumb":''
			}			
			return this.json(relist);
		}
		return this.display();	
	}
	
	//新增卡项类别
	async addcardtypeAction(){
		if(this.isPost){
			let data = this.post();
			data.o_id = this.userinfo.o_id;
			data.o_code = this.userinfo.o_code;
			//商品名称可以重复
			let res = await this.model('or_cardtype').add(data);
			return res?this.success({info:"添加成功！"}):this.fail('添加失败！');
		}
	}

	//编辑类别
	async editcardtypeAction(){
		if(this.isPost){
			let data = this.post();
			let res = await this.model('or_cardtype').where({id:data.id}).update(data);
			res?this.success({info:"编辑成功！"}):this.fail('编辑失败！');
		}
		let id = this.get('id');
		let cinfo = await this.model('or_cardtype').where({id:id}).find();
		return this.json(cinfo);
	}

	//删除类别
	async deletecardtypeAction(){
		let id = this.post('id');
		let res = await this.model('or_cardtype').where({id:id}).delete();
		return res?this.success({info:"删除成功！"}):this.fail('删除失败！');
	}	
	
  
}